package service

import (
	"a-payment/core"
	"fmt"
	"net/url"
	"sync"
)

var (
	PayCallbackServiceTemp *PayCallbackService
	PayCallbackServiceOnce sync.Once
)

type PayCallbackService struct{}

func NewPayCallbackService() *PayCallbackService {
	PayCallbackServiceOnce.Do(func() {
		PayCallbackServiceTemp = &PayCallbackService{}
	})
	return PayCallbackServiceTemp
}

// AliCallback 支付宝回调
func (m *PayCallbackService) AliCallback(params url.Values) error {
	outTradeNo, jsonStr, err := core.NewAli().Callback(params)
	if err != nil {
		return err
	}
	fmt.Println("outTradeNo=", outTradeNo)
	fmt.Println("jsonStr=", jsonStr)
	// TODO 验签通过，处理业务
	// ...
	return nil
}

// WeCallback 微信回调
func (m *PayCallbackService) WeCallback(params url.Values) error {
	return nil
}
